Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix($httpBackend): compare timeoutId with undefined in completeRequest #9979

Conversation

gyx1000
Copy link
Contributor

@gyx1000 gyx1000 commented Nov 10, 2014

httpBackend with ngMock browser.defer can never cancel the first deferredFn because the timeoutId returned by defer for the first fn is a zero value.
Compare timeoutId with undefined fix this issue.

@mary-poppins
Copy link

I'm sorry, but I wasn't able to verify your Contributor License Agreement (CLA) signature. CLA signature is required for any code contributions to AngularJS.

Please sign our CLA and ensure that the CLA signature email address and the email address in this PR's commits match.

If you signed the CLA as a corporation, please let us know the company's name.

Thanks a bunch!

PS: If you signed the CLA in the past then most likely the email addresses don't match. Please sign the CLA again or update the email address in the commit of this PR.
PS2: If you are a Googler, please sign the CLA as well to simplify the CLA verification process.

@pkozlowski-opensource
Copy link
Member

@gyx1000 could you please share a test with a scenario under which this issue shows up? This would tremendously help with reviewing suggester code change. BTW, before it get merged we would need a test so we are not introducing regressions in the future. Thnx!

@pkozlowski-opensource pkozlowski-opensource self-assigned this Nov 10, 2014
@pkozlowski-opensource
Copy link
Member

Oh, I see, this is due to https://github.com/angular/angular.js/blob/master/src/ngMock/angular-mocks.js#L65

OK, I understand the pb and the solution sounds good - still we will need a test before it can land.

@gyx1000
Copy link
Contributor Author

gyx1000 commented Nov 10, 2014

@pkozlowski-opensource thanks for review. I discovered this problem when I tried to fix the todo https://github.com/angular/angular.js/blob/master/test/ng/httpBackendSpec.js#L10 proposed by @vojtajina. If the $browser.defer mock is used instead of "fakeTimeout", the test https://github.com/angular/angular.js/blob/master/test/ng/httpBackendSpec.js#L221 use the fix. Complete todo in this PR is acceptable for the needed test ?

@@ -126,7 +126,7 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc

function completeRequest(callback, status, response, headersString, statusText) {
// cancel timeout and subsequent timeout promise resolution
timeoutId && $browserDefer.cancel(timeoutId);
timeoutId !== undefined && $browserDefer.cancel(timeoutId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

void 0, rather than undefined please

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, please write this as if (timeoutId !== void 0) $browserDefer.cancel(timeoutId); --- it's much cleaner this way. (note that we need braces around the block IIRC)

caitp added a commit to caitp/angular.js that referenced this pull request Nov 10, 2014
@caitp
Copy link
Contributor

caitp commented Nov 10, 2014

I've submitted the fixup as a PR against @gyx1000's branch too, so it should be easy to do this one way or the other. fixup look good to you @pkozlowski-opensource?

@gyx1000 gyx1000 force-pushed the compare-timeoutid-with-undefined-in-completerequest branch from 986c69a to db8ec99 Compare November 11, 2014 08:39
gyx1000 pushed a commit to gyx1000/angular.js that referenced this pull request Nov 11, 2014
@gyx1000 gyx1000 force-pushed the compare-timeoutid-with-undefined-in-completerequest branch 2 times, most recently from ebc5f32 to c93af0f Compare November 11, 2014 12:36
httpBackend with ngMock browser.defer can never cancel the first deferredFn because the timeoutId returned by defer for the first fn is a zero value.
Compare timeoutId with undefined fix this issue.
@gyx1000 gyx1000 force-pushed the compare-timeoutid-with-undefined-in-completerequest branch from c93af0f to 00182c8 Compare November 11, 2014 12:45
@pkozlowski-opensource
Copy link
Member

OK, since the fixup has a test let's move the discussion in there (#9993).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants